define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-edit").data("area", ["100%", "100%"]);//编辑
            $(".btn-add").data("area", ["100%", "100%"]); //添加
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'card/membership_card/index' + location.search,
                    add_url: 'card/membership_card/add',
                    edit_url: 'card/membership_card/edit',
                    del_url: 'card/membership_card/del',
                    multi_url: 'card/membership_card/multi',
                    import_url: 'card/membership_card/import',
                    table: 'membership_card',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'type', title: __('Type'),
                            searchList: {1:__('Type One'), 2:__('Type Two')},
                            formatter: Table.api.formatter.label
                        },
                        {field: 'month', title: __('Month'),
                            formatter: function (index, value) {
                                return value.month + '个月';
                            }
                        },
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'original_price', title: __('Original_price'), operate:'BETWEEN'},
                        {field: 'sales_price', title: __('Sales_price'), operate:'BETWEEN'},
                        {field: 'number', title: __('人脉显示'),
                            formatter: function (value, index) {
                                if(value) {
                                    return value + '个人脉显示持有人';
                                }
                                return 0;
                            }
                        },
                        {field: 'look_number', title: __('查看数量'),
                            formatter: function (value, index) {
                                if(value) {
                                    return value + '次/月直接查看他人名片权益';
                                }
                                return 0;
                            }
                        },
                        {field: 'file_capacity', title: __('附件容量'),
                            formatter: function (value, index) {
                                if(value) {
                                    return value + 'MB附件文件累计储存容量';
                                }
                                return 0;
                            }
                        },
                        {field: 'admin.nickname', title: __('Admin_uid'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            table.on('post-body.bs.table', function () {
                $(".btn-editone").data("area", ["100%", "100%"]);
                $(".btn-addone").data("area", ["100%", "100%"]);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
